
<!DOCTYPE html>
<html lang="" class="loading">
<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>JavaOOP 8 - L3SLIE</title>
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <meta name="google" content="notranslate" />
    <meta name="keywords" content="L3SLIE,"> 
    <meta name="description" content="Welcome &amp; suit yourself,Java运算符这和c语言里的差不多。
计算机的最基本用途之一就是执行数学运算，作为一门计算机语言，Java也提供了一套丰富的运算符来操纵变量。我们可以把运算符分成以下几组：

算术运算符
关系运算符,"> 
    <meta name="author" content="L3SLIE"> 
    <link rel="alternative" href="atom.xml" title="L3SLIE" type="application/atom+xml"> 
    <link rel="icon" href="/img/favicon.png"> 
    <link href="https://fonts.loli.net/css?family=Roboto+Mono|Rubik&display=swap" rel="stylesheet">
    
<link rel="stylesheet" href="//at.alicdn.com/t/font_1429596_nzgqgvnmkjb.css">

    
<link rel="stylesheet" href="//cdn.bootcss.com/animate.css/3.7.2/animate.min.css">

    
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/social-share.js/1.0.16/css/share.min.css">

    
<link rel="stylesheet" href="//cdn.bootcss.com/codemirror/5.48.4/codemirror.min.css">

    
<link rel="stylesheet" href="//cdn.bootcss.com/codemirror/5.48.4/theme/dracula.css">

    
<link rel="stylesheet" href="/css/obsidian.css">

    
<link rel="stylesheet" href="/css/ball-atom.min.css">

<meta name="generator" content="Hexo 4.2.0"></head>


<body class="loading">
    <div class="loader">
        <div class="la-ball-atom la-2x">
            <div></div>
            <div></div>
            <div></div>
            <div></div>
        </div>
    </div>
    <span id="config-title" style="display:none">L3SLIE</span>
    <div id="loader"></div>
    <div id="single">
    <div class="scrollbar gradient-bg-rev"></div>
<div id="top" style="display: block;">
    <div class="bar" style="width: 0;"></div>
    <div class="navigation animated fadeIn fast delay-1s">
        <img id="home-icon" class="icon-home" src="/img/favicon.png" alt="" data-url="http://l3slie.gitee.io">
        <div id="play-icon" title="Play/Pause" class="iconfont icon-play"></div>
        <h3 class="subtitle">JavaOOP 8</h3>
        <div class="social">
            <!--        <div class="like-icon">-->
            <!--            <a href="javascript:;" class="likeThis active"><span class="icon-like"></span><span class="count">76</span></a>-->
            <!--        </div>-->
            <div>
                <div class="share">
                    
                        <a href="javascript:;" class="iconfont icon-share1"></a>
                        <div class="share-component-cc" data-disabled="facebook,douban,linkedin,diandian,tencent,google"></div>
                    
                </div>
            </div>
        </div>
    </div>
</div>

    <div class="section">
        <div class=article-header-wrapper>
    <div class="article-header">
        <div class="article-cover animated fadeIn" style="
            animation-delay: 600ms;
            animation-duration: 1.2s;
            background-image: 
                radial-gradient(ellipse closest-side, rgba(0, 0, 0, 0.65), #100e17),
                url(/img/cover1.jpg) ">
        </div>
        <div class="else">
            <p class="animated fadeInDown">
                
                <a href="/categories/JAVA"><b>「
                    </b>JAVA<b> 」</b></a>
                
                March 16, 2020
            </p>
            <h3 class="post-title animated fadeInDown"><a href="/2020/03/16/JavaOOP-8/" title="JavaOOP 8" class="">JavaOOP 8</a>
            </h3>
            
            <p class="post-count animated fadeInDown">
                
                <span>
                    <b class="iconfont icon-text2"></b> <i>Words count</i>
                    17k
                </span>
                
                
                <span>
                    <b class="iconfont icon-timer__s"></b> <i>Reading time</i>
                    16 mins.
                </span>
                
                
                <span id="/2020/03/16/JavaOOP-8/" class="leancloud_visitors" data-flag-title="JavaOOP 8">
                    <b class="iconfont icon-read"></b> <i>Read count</i>
                    <span class="leancloud-visitors-count">100000</span>
                </span>
                
                
            </p>
            
            
            <ul class="animated fadeInDown post-tags-list" itemprop="keywords"><li class="animated fadeInDown post-tags-list-item"><a class="animated fadeInDown post-tags-list-link" href="/tags/JAVA/" rel="tag">JAVA</a></li><li class="animated fadeInDown post-tags-list-item"><a class="animated fadeInDown post-tags-list-link" href="/tags/NOTE/" rel="tag">NOTE</a></li><li class="animated fadeInDown post-tags-list-item"><a class="animated fadeInDown post-tags-list-link" href="/tags/%E9%9D%A2%E5%AF%B9%E5%AF%B9%E8%B1%A1%E7%BC%96%E7%A8%8B/" rel="tag">面对对象编程</a></li></ul>
            
        </div>
    </div>
</div>

<div class="screen-gradient-after">
    <div class="screen-gradient-content">
        <div class="screen-gradient-content-inside">
            <div class="bold-underline-links screen-gradient-sponsor">
                <p>
                    <span class="animated fadeIn delay-1s"></span>
                </p>
            </div>
        </div>
    </div>
</div>

<div class="article">
    <div class='main'>
        <div class="content markdown animated fadeIn">
            <h1 id="Java运算符"><a href="#Java运算符" class="headerlink" title="Java运算符"></a>Java运算符</h1><p>这和c语言里的差不多。</p>
<p>计算机的最基本用途之一就是执行数学运算，作为一门计算机语言，Java也提供了一套丰富的运算符来操纵变量。我们可以把运算符分成以下几组：</p>
<ul>
<li>算术运算符</li>
<li>关系运算符</li>
<li>位运算符</li>
<li>逻辑运算符</li>
<li>赋值运算符</li>
<li>其他运算符</li>
</ul>
<h2 id="算术运算符"><a href="#算术运算符" class="headerlink" title="算术运算符"></a>算术运算符</h2><p>算术运算符用在数学表达式中，它们的作用和在数学中的作用一样。下表列出了所有的算术运算符。</p>
<p>表格中的实例假设整数变量A的值为10，变量B的值为20：</p>
<table>
<thead>
<tr>
<th align="left">操作符</th>
<th align="left">描述</th>
<th align="left">例子</th>
</tr>
</thead>
<tbody><tr>
<td align="left">+</td>
<td align="left">加法 - 相加运算符两侧的值</td>
<td align="left">A + B 等于 30</td>
</tr>
<tr>
<td align="left">-</td>
<td align="left">减法 - 左操作数减去右操作数</td>
<td align="left">A – B 等于 -10</td>
</tr>
<tr>
<td align="left">*</td>
<td align="left">乘法 - 相乘操作符两侧的值</td>
<td align="left">A * B等于200</td>
</tr>
<tr>
<td align="left">/</td>
<td align="left">除法 - 左操作数除以右操作数</td>
<td align="left">B / A等于2</td>
</tr>
<tr>
<td align="left">％</td>
<td align="left">取余 - 左操作数除以右操作数的余数</td>
<td align="left">B%A等于0</td>
</tr>
<tr>
<td align="left">++</td>
<td align="left">自增: 操作数的值增加1</td>
<td align="left">B++ 或 ++B 等于 21（区别详见下文）</td>
</tr>
<tr>
<td align="left">–</td>
<td align="left">自减: 操作数的值减少1</td>
<td align="left">B– 或 –B 等于 19（区别详见下文）</td>
</tr>
</tbody></table>
<h3 id="实例"><a href="#实例" class="headerlink" title="实例"></a>实例</h3><p>下面的简单示例程序演示了算术运算符。复制并粘贴下面的 Java 程序并保存为 Test.java 文件，然后编译并运行这个程序：</p>
<pre><code class="java">public class Test {

  public static void main(String[] args) {
     int a = 10;
     int b = 20;
     int c = 25;
     int d = 25;
     System.out.println(&quot;a + b = &quot; + (a + b) );
     System.out.println(&quot;a - b = &quot; + (a - b) );
     System.out.println(&quot;a * b = &quot; + (a * b) );
     System.out.println(&quot;b / a = &quot; + (b / a) );
     System.out.println(&quot;b % a = &quot; + (b % a) );
     System.out.println(&quot;c % a = &quot; + (c % a) );
     System.out.println(&quot;a++   = &quot; +  (a++) );
     System.out.println(&quot;a--   = &quot; +  (a--) );
     // 查看  d++ 与 ++d 的不同
     System.out.println(&quot;d++   = &quot; +  (d++) );
     System.out.println(&quot;++d   = &quot; +  (++d) );
  }
}</code></pre>
<p>以上实例编译运行结果如下：</p>
<pre><code class="java">a + b = 30
a - b = -10
a * b = 200
b / a = 2
b % a = 0
c % a = 5
a++   = 10
a--   = 11
d++   = 25
++d   = 27</code></pre>
<h3 id="自增自减运算符"><a href="#自增自减运算符" class="headerlink" title="自增自减运算符"></a>自增自减运算符</h3><p><strong>1、自增（++）自减（–）运算符</strong>是一种特殊的算术运算符，在算术运算符中需要两个操作数来进行运算，而自增自减运算符是一个操作数。</p>
<pre><code class="java">public class selfAddMinus{
    public static void main(String[] args){
        int a = 3;//定义一个变量；
        int b = ++a;//自增运算
        int c = 3;
        int d = --c;//自减运算
        System.out.println(&quot;进行自增运算后的值等于&quot;+b);
        System.out.println(&quot;进行自减运算后的值等于&quot;+d);
    }
}</code></pre>
<p>运行结果为：</p>
<pre><code class="java">进行自增运算后的值等于4
进行自减运算后的值等于2</code></pre>
<p>解析：</p>
<ul>
<li>int b = ++a; 拆分运算过程为: a=a+1=4; b=a=4, 最后结果为b=4,a=4</li>
<li>int d = –c; 拆分运算过程为: c=c-1=2; d=c=2, 最后结果为d=2,c=2</li>
</ul>
<p><strong>2、前缀自增自减法(++a,–a):</strong> 先进行自增或者自减运算，再进行表达式运算。</p>
<p><strong>3、后缀自增自减法(a++,a–):</strong> 先进行表达式运算，再进行自增或者自减运算 </p>
<p>实例：</p>
<pre><code class="java">public class selfAddMinus{
    public static void main(String[] args){
        int a = 5;//定义一个变量；
        int b = 5;
        int x = 2*++a;
        int y = 2*b++;
        System.out.println(&quot;自增运算符前缀运算后a=&quot;+a+&quot;,x=&quot;+x);
        System.out.println(&quot;自增运算符后缀运算后b=&quot;+b+&quot;,y=&quot;+y);
    }
}</code></pre>
<p>运行结果为：</p>
<pre><code class="java">自增运算符前缀运算后a=6，x=12
自增运算符后缀运算后b=6，y=10</code></pre>
<hr>
<h2 id="关系运算符"><a href="#关系运算符" class="headerlink" title="关系运算符"></a>关系运算符</h2><p>下表为Java支持的关系运算符</p>
<p>表格中的实例整数变量A的值为10，变量B的值为20：</p>
<table>
<thead>
<tr>
<th align="left">运算符</th>
<th align="left">描述</th>
<th align="left">例子</th>
</tr>
</thead>
<tbody><tr>
<td align="left">==</td>
<td align="left">检查如果两个操作数的值是否相等，如果相等则条件为真。</td>
<td align="left">（A == B）为假。</td>
</tr>
<tr>
<td align="left">!=</td>
<td align="left">检查如果两个操作数的值是否相等，如果值不相等则条件为真。</td>
<td align="left">(A != B) 为真。</td>
</tr>
<tr>
<td align="left">&gt;</td>
<td align="left">检查左操作数的值是否大于右操作数的值，如果是那么条件为真。</td>
<td align="left">（A&gt; B）为假。</td>
</tr>
<tr>
<td align="left">&lt;</td>
<td align="left">检查左操作数的值是否小于右操作数的值，如果是那么条件为真。</td>
<td align="left">（A &lt;B）为真。</td>
</tr>
<tr>
<td align="left">&gt;=</td>
<td align="left">检查左操作数的值是否大于或等于右操作数的值，如果是那么条件为真。</td>
<td align="left">（A&gt; = B）为假。</td>
</tr>
<tr>
<td align="left">&lt;=</td>
<td align="left">检查左操作数的值是否小于或等于右操作数的值，如果是那么条件为真。</td>
<td align="left">（A &lt;= B）为真。</td>
</tr>
</tbody></table>
<h3 id="实例-1"><a href="#实例-1" class="headerlink" title="实例"></a>实例</h3><p>下面的简单示例程序演示了关系运算符。复制并粘贴下面的Java程序并保存为Test.java文件，然后编译并运行这个程序：</p>
<pre><code class="java">public class Test {

  public static void main(String[] args) {
     int a = 10;
     int b = 20;
     System.out.println(&quot;a == b = &quot; + (a == b) );
     System.out.println(&quot;a != b = &quot; + (a != b) );
     System.out.println(&quot;a &gt; b = &quot; + (a &gt; b) );
     System.out.println(&quot;a &lt; b = &quot; + (a &lt; b) );
     System.out.println(&quot;b &gt;= a = &quot; + (b &gt;= a) );
     System.out.println(&quot;b &lt;= a = &quot; + (b &lt;= a) );
  }
}</code></pre>
<p>以上实例编译运行结果如下：</p>
<pre><code class="java">a == b = false
a != b = true
a &gt; b = false
a &lt; b = true
b &gt;= a = true
b &lt;= a = false</code></pre>
<hr>
<h2 id="位运算符"><a href="#位运算符" class="headerlink" title="位运算符"></a>位运算符</h2><p>Java定义了位运算符，应用于整数类型(int)，长整型(long)，短整型(short)，字符型(char)，和字节型(byte)等类型。</p>
<p>位运算符作用在所有的位上，并且按位运算。假设a = 60，b = 13;它们的二进制格式表示将如下：</p>
<pre><code class="java">A = 0011 1100
B = 0000 1101
-----------------
A&amp;B = 0000 1100
A | B = 0011 1101
A ^ B = 0011 0001
~A= 1100 0011</code></pre>
<p>下表列出了位运算符的基本运算，假设整数变量 A 的值为 60 和变量 B 的值为 13：</p>
<table>
<thead>
<tr>
<th align="left">操作符</th>
<th align="left">描述</th>
<th align="left">例子</th>
</tr>
</thead>
<tbody><tr>
<td align="left">＆</td>
<td align="left">如果相对应位都是1，则结果为1，否则为0</td>
<td align="left">（A＆B），得到12，即0000 1100</td>
</tr>
<tr>
<td align="left">|</td>
<td align="left">如果相对应位都是 0，则结果为 0，否则为 1</td>
<td align="left">（A | B）得到61，即 0011 1101</td>
</tr>
<tr>
<td align="left">^</td>
<td align="left">如果相对应位值相同，则结果为0，否则为1</td>
<td align="left">（A ^ B）得到49，即 0011 0001</td>
</tr>
<tr>
<td align="left">〜</td>
<td align="left">按位取反运算符翻转操作数的每一位，即0变成1，1变成0。</td>
<td align="left">（〜A）得到-61，即1100 0011</td>
</tr>
<tr>
<td align="left">&lt;&lt;</td>
<td align="left">按位左移运算符。左操作数按位左移右操作数指定的位数。</td>
<td align="left">A &lt;&lt; 2得到240，即 1111 0000</td>
</tr>
<tr>
<td align="left">&gt;&gt;</td>
<td align="left">按位右移运算符。左操作数按位右移右操作数指定的位数。</td>
<td align="left">A &gt;&gt; 2得到15即 1111</td>
</tr>
<tr>
<td align="left">&gt;&gt;&gt;</td>
<td align="left">按位右移补零操作符。左操作数的值按右操作数指定的位数右移，移动得到的空位以零填充。</td>
<td align="left">A&gt;&gt;&gt;2得到15即0000 1111</td>
</tr>
</tbody></table>
<h3 id="实例-2"><a href="#实例-2" class="headerlink" title="实例"></a>实例</h3><p>下面的简单示例程序演示了位运算符。复制并粘贴下面的Java程序并保存为Test.java文件，然后编译并运行这个程序：</p>
<pre><code class="java">public class Test {
  public static void main(String[] args) {
     int a = 60; /* 60 = 0011 1100 */ 
     int b = 13; /* 13 = 0000 1101 */
     int c = 0;
     c = a &amp; b;       /* 12 = 0000 1100 */
     System.out.println(&quot;a &amp; b = &quot; + c );

     c = a | b;       /* 61 = 0011 1101 */
     System.out.println(&quot;a | b = &quot; + c );

     c = a ^ b;       /* 49 = 0011 0001 */
     System.out.println(&quot;a ^ b = &quot; + c );

     c = ~a;          /*-61 = 1100 0011 */
     System.out.println(&quot;~a = &quot; + c );

     c = a &lt;&lt; 2;     /* 240 = 1111 0000 */
     System.out.println(&quot;a &lt;&lt; 2 = &quot; + c );

     c = a &gt;&gt; 2;     /* 15 = 1111 */
     System.out.println(&quot;a &gt;&gt; 2  = &quot; + c );

     c = a &gt;&gt;&gt; 2;     /* 15 = 0000 1111 */
     System.out.println(&quot;a &gt;&gt;&gt; 2 = &quot; + c );
  }
} </code></pre>
<pre><code class="java">以上实例编译运行结果如下：

a &amp; b = 12
a | b = 61
a ^ b = 49
~a = -61
a &lt;&lt; 2 = 240
a &gt;&gt; 2  = 15
a &gt;&gt;&gt; 2 = 15</code></pre>
<hr>
<h2 id="逻辑运算符"><a href="#逻辑运算符" class="headerlink" title="逻辑运算符"></a>逻辑运算符</h2><p>下表列出了逻辑运算符的基本运算，假设布尔变量A为真，变量B为假</p>
<table>
<thead>
<tr>
<th align="left">操作符</th>
<th align="left">描述</th>
<th align="left">例子</th>
</tr>
</thead>
<tbody><tr>
<td align="left">&amp;&amp;</td>
<td align="left">称为逻辑与运算符。当且仅当两个操作数都为真，条件才为真。</td>
<td align="left">（A &amp;&amp; B）为假。</td>
</tr>
<tr>
<td align="left">| |</td>
<td align="left">称为逻辑或操作符。如果任何两个操作数任何一个为真，条件为真。</td>
<td align="left">（A | | B）为真。</td>
</tr>
<tr>
<td align="left">！</td>
<td align="left">称为逻辑非运算符。用来反转操作数的逻辑状态。如果条件为true，则逻辑非运算符将得到false。</td>
<td align="left">！（A &amp;&amp; B）为真。</td>
</tr>
</tbody></table>
<h3 id="实例-3"><a href="#实例-3" class="headerlink" title="实例"></a>实例</h3><p>下面的简单示例程序演示了逻辑运算符。复制并粘贴下面的Java程序并保存为Test.java文件，然后编译并运行这个程序：</p>
<pre><code class="java">public class Test {
  public static void main(String[] args) {
     boolean a = true;
     boolean b = false;
     System.out.println(&quot;a &amp;&amp; b = &quot; + (a&amp;&amp;b));
     System.out.println(&quot;a || b = &quot; + (a||b) );
     System.out.println(&quot;!(a &amp;&amp; b) = &quot; + !(a &amp;&amp; b));
  }
}</code></pre>
<p>以上实例编译运行结果如下：</p>
<pre><code class="java">a &amp;&amp; b = false
a || b = true
!(a &amp;&amp; b) = true</code></pre>
<h3 id="短路逻辑运算符"><a href="#短路逻辑运算符" class="headerlink" title="短路逻辑运算符"></a>短路逻辑运算符</h3><p>当使用与逻辑运算符时，在两个操作数都为true时，结果才为true，但是当得到第一个操作为false时，其结果就必定是false，这时候就不会再判断第二个操作了。</p>
<pre><code class="java">public class LuoJi{
    public static void main(String[] args){
        int a = 5;//定义一个变量；
        boolean b = (a&lt;4)&amp;&amp;(a++&lt;10);
        System.out.println(&quot;使用短路逻辑运算符的结果为&quot;+b);
        System.out.println(&quot;a的结果为&quot;+a);
    }
}</code></pre>
<p>运行结果为：</p>
<pre><code class="java">使用短路逻辑运算符的结果为false
a的结果为5</code></pre>
<blockquote>
<p><strong>解析：</strong> 该程序使用到了短路逻辑运算符(&amp;&amp;)，首先判断 a&lt;4 的结果为 false，则 b 的结果必定是 false，所以不再执行第二个操作 a++&lt;10 的判断，所以 a 的值为 5。</p>
</blockquote>
<hr>
<h2 id="赋值运算符"><a href="#赋值运算符" class="headerlink" title="赋值运算符"></a>赋值运算符</h2><p>下面是Java语言支持的赋值运算符：</p>
<table>
<thead>
<tr>
<th align="left">操作符</th>
<th align="left">描述</th>
<th align="left">例子</th>
</tr>
</thead>
<tbody><tr>
<td align="left">=</td>
<td align="left">简单的赋值运算符，将右操作数的值赋给左侧操作数</td>
<td align="left">C = A + B将把A + B得到的值赋给C</td>
</tr>
<tr>
<td align="left">+ =</td>
<td align="left">加和赋值操作符，它把左操作数和右操作数相加赋值给左操作数</td>
<td align="left">C + = A等价于C = C + A</td>
</tr>
<tr>
<td align="left">- =</td>
<td align="left">减和赋值操作符，它把左操作数和右操作数相减赋值给左操作数</td>
<td align="left">C - = A等价于C = C - A</td>
</tr>
<tr>
<td align="left">* =</td>
<td align="left">乘和赋值操作符，它把左操作数和右操作数相乘赋值给左操作数</td>
<td align="left">C * = A等价于C = C * A</td>
</tr>
<tr>
<td align="left">/ =</td>
<td align="left">除和赋值操作符，它把左操作数和右操作数相除赋值给左操作数</td>
<td align="left">C / = A，C 与 A 同类型时等价于 C = C / A</td>
</tr>
<tr>
<td align="left">（％）=</td>
<td align="left">取模和赋值操作符，它把左操作数和右操作数取模后赋值给左操作数</td>
<td align="left">C％= A等价于C = C％A</td>
</tr>
<tr>
<td align="left">&lt;&lt; =</td>
<td align="left">左移位赋值运算符</td>
<td align="left">C &lt;&lt; = 2等价于C = C &lt;&lt; 2</td>
</tr>
<tr>
<td align="left">&gt;&gt; =</td>
<td align="left">右移位赋值运算符</td>
<td align="left">C &gt;&gt; = 2等价于C = C &gt;&gt; 2</td>
</tr>
<tr>
<td align="left">＆=</td>
<td align="left">按位与赋值运算符</td>
<td align="left">C＆= 2等价于C = C＆2</td>
</tr>
<tr>
<td align="left">^ =</td>
<td align="left">按位异或赋值操作符</td>
<td align="left">C ^ = 2等价于C = C ^ 2</td>
</tr>
<tr>
<td align="left">| =</td>
<td align="left">按位或赋值操作符</td>
<td align="left">C | = 2等价于C = C | 2</td>
</tr>
</tbody></table>
<h3 id="实例-4"><a href="#实例-4" class="headerlink" title="实例"></a>实例</h3><p>面的简单示例程序演示了赋值运算符。复制并粘贴下面的Java程序并保存为Test.java文件，然后编译并运行这个程序：</p>
<pre><code class="java">public class Test {
    public static void main(String[] args) {
        int a = 10;
        int b = 20;
        int c = 0;
        c = a + b;
        System.out.println(&quot;c = a + b = &quot; + c );
        c += a ;
        System.out.println(&quot;c += a  = &quot; + c );
        c -= a ;
        System.out.println(&quot;c -= a = &quot; + c );
        c *= a ;
        System.out.println(&quot;c *= a = &quot; + c );
        a = 10;
        c = 15;
        c /= a ;
        System.out.println(&quot;c /= a = &quot; + c );
        a = 10;
        c = 15;
        c %= a ;
        System.out.println(&quot;c %= a  = &quot; + c );
        c &lt;&lt;= 2 ;
        System.out.println(&quot;c &lt;&lt;= 2 = &quot; + c );
        c &gt;&gt;= 2 ;
        System.out.println(&quot;c &gt;&gt;= 2 = &quot; + c );
        c &gt;&gt;= 2 ;
        System.out.println(&quot;c &gt;&gt;= 2 = &quot; + c );
        c &amp;= a ;
        System.out.println(&quot;c &amp;= a  = &quot; + c );
        c ^= a ;
        System.out.println(&quot;c ^= a   = &quot; + c );
        c |= a ;
        System.out.println(&quot;c |= a   = &quot; + c );
    }
}</code></pre>
<p>以上实例编译运行结果如下：</p>
<pre><code class="java">c = a + b = 30
c += a  = 40
c -= a = 30
c *= a = 300
c /= a = 1
c %= a  = 5
c &lt;&lt;= 2 = 20
c &gt;&gt;= 2 = 5
c &gt;&gt;= 2 = 1
c &amp;= a  = 0
c ^= a   = 10
c |= a   = 10</code></pre>
<hr>
<h2 id="条件运算符（-）"><a href="#条件运算符（-）" class="headerlink" title="条件运算符（?:）"></a>条件运算符（?:）</h2><p>条件运算符也被称为三元运算符。该运算符有3个操作数，并且需要判断布尔表达式的值。该运算符的主要是决定哪个值应该赋值给变量。</p>
<pre><code class="java">variable x = (expression) ? value if true : value if false</code></pre>
<p>e.g.</p>
<pre><code class="java">public class Test {
   public static void main(String[] args){
      int a , b;
      a = 10;
      // 如果 a 等于 1 成立，则设置 b 为 20，否则为 30
      b = (a == 1) ? 20 : 30;
      System.out.println( &quot;Value of b is : &quot; +  b );

      // 如果 a 等于 10 成立，则设置 b 为 20，否则为 30
      b = (a == 10) ? 20 : 30;
      System.out.println( &quot;Value of b is : &quot; + b );
   }
}</code></pre>
<p>以上实例编译运行结果如下：</p>
<pre><code class="java">Value of b is : 30
Value of b is : 20</code></pre>
<hr>
<h2 id="instanceof-运算符"><a href="#instanceof-运算符" class="headerlink" title="instanceof 运算符"></a>instanceof 运算符</h2><p>该运算符用于操作对象实例，检查该对象是否是一个特定类型（类类型或接口类型）。</p>
<p>instanceof运算符使用格式如下：</p>
<pre><code>( Object reference variable ) instanceof  (class/interface type)</code></pre><p>如果运算符左侧变量所指的对象，是操作符右侧类或接口(class/interface)的一个对象，那么结果为真。</p>
<p>下面是一个例子：</p>
<pre><code>String name = &quot;James&quot;;
boolean result = name instanceof String; // 由于 name 是 String 类型，所以返回真</code></pre><p>如果被比较的对象兼容于右侧类型,该运算符仍然返回true。</p>
<p>看下面的例子：</p>
<pre><code class="java">class Vehicle {}

public class Car extends Vehicle {
   public static void main(String[] args){
      Vehicle a = new Car();
      boolean result =  a instanceof Car;
      System.out.println( result);
   }
}</code></pre>
<p>以上实例编译运行结果如下：</p>
<pre><code class="java">true</code></pre>
<hr>
<h2 id="Java运算符优先级"><a href="#Java运算符优先级" class="headerlink" title="Java运算符优先级"></a>Java运算符优先级</h2><p>当多个运算符出现在一个表达式中，谁先谁后呢？这就涉及到运算符的优先级别的问题。在一个多运算符的表达式中，运算符优先级不同会导致最后得出的结果差别甚大。</p>
<p>例如，（1+3）＋（3+2）*2，这个表达式如果按加号最优先计算，答案就是 18，如果按照乘号最优先，答案则是 14。</p>
<p>再如，x = 7 + 3 * 2;这里x得到13，而不是20，因为乘法运算符比加法运算符有较高的优先级，所以先计算3 * 2得到6，然后再加7。</p>
<p>下表中具有最高优先级的运算符在的表的最上面，最低优先级的在表的底部。</p>
<table>
<thead>
<tr>
<th align="left">类别</th>
<th align="left">操作符</th>
<th align="left">关联性</th>
</tr>
</thead>
<tbody><tr>
<td align="left">后缀</td>
<td align="left">() [] . (点操作符)</td>
<td align="left">左到右</td>
</tr>
<tr>
<td align="left">一元</td>
<td align="left">+ + - ！〜</td>
<td align="left">从右到左</td>
</tr>
<tr>
<td align="left">乘性</td>
<td align="left">* /％</td>
<td align="left">左到右</td>
</tr>
<tr>
<td align="left">加性</td>
<td align="left">+ -</td>
<td align="left">左到右</td>
</tr>
<tr>
<td align="left">移位</td>
<td align="left">&gt;&gt; &gt;&gt;&gt;  &lt;&lt;</td>
<td align="left">左到右</td>
</tr>
<tr>
<td align="left">关系</td>
<td align="left">&gt;&gt; = &lt;&lt; =</td>
<td align="left">左到右</td>
</tr>
<tr>
<td align="left">相等</td>
<td align="left">== !=</td>
<td align="left">左到右</td>
</tr>
<tr>
<td align="left">按位与</td>
<td align="left">＆</td>
<td align="left">左到右</td>
</tr>
<tr>
<td align="left">按位异或</td>
<td align="left">^</td>
<td align="left">左到右</td>
</tr>
<tr>
<td align="left">按位或</td>
<td align="left">|</td>
<td align="left">左到右</td>
</tr>
<tr>
<td align="left">逻辑与</td>
<td align="left">&amp;&amp;</td>
<td align="left">左到右</td>
</tr>
<tr>
<td align="left">逻辑或</td>
<td align="left">| |</td>
<td align="left">左到右</td>
</tr>
<tr>
<td align="left">条件</td>
<td align="left">？：</td>
<td align="left">从右到左</td>
</tr>
<tr>
<td align="left">赋值</td>
<td align="left">= + = - = * = / =％= &gt;&gt; = &lt;&lt; =＆= ^ = | =</td>
<td align="left">从右到左</td>
</tr>
<tr>
<td align="left">逗号</td>
<td align="left">，</td>
<td align="left">左到右</td>
</tr>
</tbody></table>
<h1 id="–NEXT–"><a href="#–NEXT–" class="headerlink" title="–NEXT–"></a>–NEXT–</h1><p>Java循环结构</p>

            <!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->
            <audio id="audio" loop="1" preload="auto" controls="controls"
                data-autoplay="false">
                <source type="audio/mpeg" src="">
            </audio>
            
            <ul id="audio-list" style="display:none">
                
                
                <li title='0' data-url='/statics/i saw you in a dream.mp3'></li>
                
                    
            </ul>
            
            
            
            <div id="vcomments"></div>
            
        </div>
        <div class="sidebar">
            <div class="box animated fadeInRight">
                <div class="subbox">
                    <img src="/img/avatar.jpg" height=300 width=300></img>
                    <p>L3SLIE</p>
                    <span>Life Long & Pwn</span>
                    <dl>
                        <dd><a href="https://github.com/13slie" target="_blank"><span
                                    class=" iconfont icon-github"></span></a></dd>
                        <dd><a href="" target="_blank"><span
                                    class=" iconfont icon-twitter"></span></a></dd>
                        <dd><a href="https://stackexchange.com/users/17805607/l3slie" target="_blank"><span
                                    class=" iconfont icon-stack-overflow"></span></a></dd>
                    </dl>
                </div>
                <ul>
                    <li><a href="/">46 <p>Articles</p></a></li>
                    <li><a href="/categories">13 <p>Categories</p></a></li>
                    <li><a href="/tags">20 <p>Tags</p></a></li>
                    <br><span><b><p>友链博客</p></b></span><br>
                    <span><u><p><a href="http://rdd.xjusec.club/" target="_blank">Rdd</a></p></u></span>
                    <span><u><p><a href="http://www.xjusec.club/" target="_blank">XJUSEC</a></p></u></span>
                    <span><u><p><a href="http://www.r1ght0us.xyz/" target="_blank">r1ght0us</a></p></u></span>
                </ul>
            </div>
            
            
            
            <div class="box sticky animated fadeInRight faster">
                <div id="toc" class="subbox">
                    <h4>Contents</h4>
                    <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#Java运算符"><span class="toc-number">1.</span> <span class="toc-text">Java运算符</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#算术运算符"><span class="toc-number">1.1.</span> <span class="toc-text">算术运算符</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#实例"><span class="toc-number">1.1.1.</span> <span class="toc-text">实例</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#自增自减运算符"><span class="toc-number">1.1.2.</span> <span class="toc-text">自增自减运算符</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#关系运算符"><span class="toc-number">1.2.</span> <span class="toc-text">关系运算符</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#实例-1"><span class="toc-number">1.2.1.</span> <span class="toc-text">实例</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#位运算符"><span class="toc-number">1.3.</span> <span class="toc-text">位运算符</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#实例-2"><span class="toc-number">1.3.1.</span> <span class="toc-text">实例</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#逻辑运算符"><span class="toc-number">1.4.</span> <span class="toc-text">逻辑运算符</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#实例-3"><span class="toc-number">1.4.1.</span> <span class="toc-text">实例</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#短路逻辑运算符"><span class="toc-number">1.4.2.</span> <span class="toc-text">短路逻辑运算符</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#赋值运算符"><span class="toc-number">1.5.</span> <span class="toc-text">赋值运算符</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#实例-4"><span class="toc-number">1.5.1.</span> <span class="toc-text">实例</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#条件运算符（-）"><span class="toc-number">1.6.</span> <span class="toc-text">条件运算符（?:）</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#instanceof-运算符"><span class="toc-number">1.7.</span> <span class="toc-text">instanceof 运算符</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Java运算符优先级"><span class="toc-number">1.8.</span> <span class="toc-text">Java运算符优先级</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#–NEXT–"><span class="toc-number">2.</span> <span class="toc-text">–NEXT–</span></a></li></ol>
                </div>
            </div>
            
            
        </div>
    </div>
</div>

    </div>
</div>
    <div id="back-to-top" class="animated fadeIn faster">
        <div class="flow"></div>
        <span class="percentage animated fadeIn faster">0%</span>
        <span class="iconfont icon-top02 animated fadeIn faster"></span>
    </div>
</body>
<footer>
    <p class="copyright" id="copyright">
		<span id="timeDate">载入天数...</span><span id="times">载入时分秒...</span>
		<script>
		var now = new Date(); 
		function createtime() { 
			var grt= new Date("01/10/2020 00:00:00");//在此处修改你的建站时间
			now.setTime(now.getTime()+250); 
			days = (now - grt ) / 1000 / 60 / 60 / 24; dnum = Math.floor(days); 
			hours = (now - grt ) / 1000 / 60 / 60 - (24 * dnum); hnum = Math.floor(hours); 
			if(String(hnum).length ==1 ){hnum = "0" + hnum;} minutes = (now - grt ) / 1000 /60 - (24 * 60 * dnum) - (60 * hnum); 
			mnum = Math.floor(minutes); if(String(mnum).length ==1 ){mnum = "0" + mnum;} 
			seconds = (now - grt ) / 1000 - (24 * 60 * 60 * dnum) - (60 * 60 * hnum) - (60 * mnum); 
			snum = Math.round(seconds); if(String(snum).length ==1 ){snum = "0" + snum;} 
			document.getElementById("timeDate").innerHTML = "本站已安全运行 "+dnum+" 天 "; 
			document.getElementById("times").innerHTML = hnum + " 小时 " + mnum + " 分 " + snum + " 秒"; 
		} 
		setInterval("createtime()",250);
		</script>
        &copy; 2020
        <span class="gradient-text">
            L3SLIE
        </span>❤
        Powered by <a href="http://hexo.io/" title="Hexo" target="_blank" rel="noopener">Hexo</a>
        Theme
        <span class="gradient-text">
            <a href="https://github.com/TriDiamond/hexo-theme-obsidian" title="Obsidian" target="_blank" rel="noopener">Obsidian</a>
        </span>
        <small><a href="https://github.com/TriDiamond/hexo-theme-obsidian/blob/master/CHANGELOG.md" title="v1.4.3" target="_blank" rel="noopener">v1.4.3</a></small>
    </p>
</footer>

<script type="text/javascript" src="https://cdn.bootcss.com/mathjax/2.7.6/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<script>
  MathJax.Hub.Config({
    "HTML-CSS": {
      preferredFont: "TeX",
      availableFonts: ["STIX", "TeX"],
      linebreaks: {
        automatic: true
      },
      EqnChunk: (MathJax.Hub.Browser.isMobile ? 10 : 50)
    },
    tex2jax: {
      inlineMath: [
        ["$", "$"],
        ["\\(", "\\)"]
      ],
      processEscapes: true,
      ignoreClass: "tex2jax_ignore|dno",
      skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
    },
    TeX: {
      noUndefined: {
        attributes: {
          mathcolor: "red",
          mathbackground: "#FFEEEE",
          mathsize: "90%"
        }
      },
      Macros: {
        href: "{}"
      }
    },
    messageStyle: "none"
  });
</script>
<script>
  function initialMathJax() {
    MathJax.Hub.Queue(function () {
      var all = MathJax.Hub.getAllJax(),
        i;
      // console.log(all);
      for (i = 0; i < all.length; i += 1) {
        console.log(all[i].SourceElement().parentNode)
        all[i].SourceElement().parentNode.className += ' has-jax';
      }
    });
  }

  function reprocessMathJax() {
    if (typeof MathJax !== 'undefined') {
      MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
    }
  }
</script>




<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="/js/plugin.js"></script>
<script src="/js/obsidian.js"></script>
<script src="/js/jquery.truncate.js"></script>
<script src="/js/search.js"></script>


<script src="//cdn.bootcss.com/typed.js/2.0.10/typed.min.js"></script>


<script src="//cdn.bootcss.com/blueimp-md5/2.12.0/js/md5.min.js"></script>


<script src="//cdnjs.cloudflare.com/ajax/libs/social-share.js/1.0.16/js/social-share.min.js"></script>


<script src="https://cdn.bootcss.com/codemirror/5.48.4/codemirror.min.js"></script>

    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/javascript/javascript.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/css/css.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/xml/xml.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/htmlmixed/htmlmixed.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/clike/clike.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/php/php.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/shell/shell.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/python/python.min.js"></script>




    
<script src="/js/busuanzi.min.js"></script>

    <script>
        $(document).ready(function () {
            if ($('span[id^="busuanzi_"]').length) {
                initialBusuanzi();
            }
        });
    </script>



<link rel="stylesheet" href="//cdn.bootcss.com/photoswipe/4.1.3/photoswipe.min.css">
<link rel="stylesheet" href="//cdn.bootcss.com/photoswipe/4.1.3/default-skin/default-skin.min.css">


<script src="//cdn.bootcss.com/photoswipe/4.1.3/photoswipe.min.js"></script>
<script src="//cdn.bootcss.com/photoswipe/4.1.3/photoswipe-ui-default.min.js"></script>


<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">
    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>
    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">
        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>
        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">
            <div class="pswp__top-bar">
                <!--  Controls are self-explanatory. Order can be changed. -->
                <div class="pswp__counter"></div>
                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>
                <button class="pswp__button pswp__button--share" title="Share"></button>
                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>
                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>
                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                      <div class="pswp__preloader__cut">
                        <div class="pswp__preloader__donut"></div>
                      </div>
                    </div>
                </div>
            </div>
            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div> 
            </div>
            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>
            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>
            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>
        </div>
    </div>
</div>







<script>
    function initialTyped () {
        var typedTextEl = $('.typed-text');
        if (typedTextEl && typedTextEl.length > 0) {
            var typed = new Typed('.typed-text', {
                strings: ["Life Long &amp; Pwn", "生命不息，破解不止"],
                typeSpeed: 90,
                loop: true,
                loopCount: Infinity,
                backSpeed: 20,
            });
        }
    }

    if ($('.article-header') && $('.article-header').length) {
        $(document).ready(function () {
            initialTyped();
        });
    }
</script>


    
<script src="//unpkg.com/valine/dist/Valine.min.js"></script>

    <script>

        var valine = new Valine();

        function initValine(path) {
            if (!path) path = window.location.pathname;
            let language = '';
            if (!language) {
                language = 'en';
            } else {
                language = language.toLowerCase();
            }
            valine.init({
                el: '#vcomments',
                appId: 'GnPlbHQ9xAWEoCDC8rR3zALj-gzGzoHsz',
                appKey: 'Nygd2awSxr9ioTDtvbH6hE0l',
                notify: 'false',
                verify: 'false',
                avatar: 'mm',
                placeholder: 'feel free to comment~',
                visitor: 'true',
                path: path,
                lang: language
            });
        }

        $(document).ready(function () {
            initValine();
        });
    </script>



</html>
<!-- 页面点击小红心 -->
<script type="text/javascript" src="/js/love.js"></script>
<!-- 烟火效果 -->
<canvas class="fireworks" style="position: fixed;left: 0;top: 0;z-index: 1; pointer-events: none;" ></canvas> 
<script type="text/javascript" src="//cdn.bootcss.com/animejs/2.2.0/anime.min.js"></script> 
<script type="text/javascript" src="/js/fireworks.js"></script>
<!--自定义标题-->
<script type="text/javascript" src="\js\title.js"></script>
